<template>
    <view class="content-swiper-bottom-message-gift" @click="uploadImg">
        <slot name="gift-box"></slot>
    </view>
</template>
    
<script setup>
import { reactive, getCurrentInstance, onMounted } from "vue"
import { getAuthorization, setAuthorization } from "@/utils/auth.js"

import PaySend from '@/pages/home/components/paySend/index.vue'

import { onLoad } from '@dcloudio/uni-app'
const state = reactive({
    show: false,
    curIndex: false
})

const emits = defineEmits(['successImg'])

onLoad((options) => {

})

const uploadImg = () => {
    // 上传文件
    let tokenObj = getAuthorization("token") ? JSON.parse(getAuthorization("token")) : ""
    let token = tokenObj.AccessToken
    uni.chooseImage({
        count: 1, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], //从相册选择
        success: function (res) {
            uni.uploadFile({
                url: '/api/app/api/G/user-heibai/v1/Files', //仅为示例，非真实的接口地址
                filePath: res.tempFilePaths[0],
                name: 'file',
                header: {
                    "Authorization": "Bearer " + token
                },
                formData: {
                    'groupCode': '99999999'
                },
                success: (uploadFileRes) => {
                    let data = JSON.parse(uploadFileRes.data)
                    if (data.code == 200) {
                        emits("successImg",data)
                    }
                }
            });
        }
    });
}

</script>
    
<style lang="scss" scoped></style>
    